package gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import Controlador.Controlador;
import Controlador.ControladorRodamiento;
import beans.Rodamiento;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModificarRodamientosFrame extends Vista{

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JFrame ventana = new JFrame();
	
	

	public static void main(String[] args) {
		ModificarRodamientosFrame m = new ModificarRodamientosFrame();
		Controlador rodamiento=new ControladorRodamiento(m);
		m.addcontroladorrodamiento(rodamiento);
		
	} 
	

	public ModificarRodamientosFrame()
	{
		super();
		initGUI();
	}
	
	
	private void initGUI() {
		try {
			{
				jPanel1 = new JPanel();
				ventana.getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setLayout(null);
				jPanel1.setPreferredSize(new java.awt.Dimension(428, 267));
				{
					lblCodRodamiento = new JLabel();
					jPanel1.add(lblCodRodamiento);
					lblCodRodamiento.setText("Codigo Rodamiento:");
					lblCodRodamiento.setBounds(18, 33, 113, 16);
				}
				{
					txtCodRodamiento = new JTextField();
					jPanel1.add(txtCodRodamiento);
					txtCodRodamiento.setBounds(143, 29, 166, 20);
				}
				{
					btnBuscarRodamiento = new JButton();
					jPanel1.add(btnBuscarRodamiento);
					btnBuscarRodamiento.setText("Buscar");
					btnBuscarRodamiento.setBounds(331, 26, 86, 26);
					btnBuscarRodamiento.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							btnBuscarRodamientoActionPerformed(evt);
						}
					});
				}
				{
					lblDesc = new JLabel();
					jPanel1.add(lblDesc);
					lblDesc.setText("Descripcion:");
					lblDesc.setBounds(12, 121, 113, 16);
				}
				{
					txtDesc = new JTextField();
					jPanel1.add(txtDesc);
					txtDesc.setBounds(143, 119, 166, 20);
				}
				{
					lblMarca = new JLabel();
					jPanel1.add(lblMarca);
					lblMarca.setText("Marca:");
					lblMarca.setBounds(12, 153, 113, 16);
				}
				{
					txtMarca = new JTextField();
					jPanel1.add(txtMarca);
					txtMarca.setBounds(143, 151, 166, 20);
				}
				{
					lblOrigen = new JLabel();
					jPanel1.add(lblOrigen);
					lblOrigen.setText("Origen:");
					lblOrigen.setBounds(12, 185, 113, 16);
				}
				{
					txtOrigen = new JTextField();
					jPanel1.add(txtOrigen);
					txtOrigen.setBounds(143, 183, 166, 20);
				}
				{
					btnModificarRodamiento = new JButton();
					jPanel1.add(btnModificarRodamiento);
					btnModificarRodamiento.setText("Modificar Rodamiento");
					btnModificarRodamiento.setBounds(56, 220, 158, 26);
					btnModificarRodamiento.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							btnModificarRodamientoActionPerformed(evt);
						}
					});
				}
				{
					btnCancelar = new JButton();
					jPanel1.add(btnCancelar);
					btnCancelar.setText("Cancelar");
					btnCancelar.setBounds(268, 220, 106, 26);
					btnCancelar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							btnCancelarActionPerformed(evt);
						}
					});
				}
				{
					jTextField1 = new JTextField();
					jPanel1.add(jTextField1);
					jTextField1.setBounds(143, 87, 166, 20);
					jTextField1.setEditable(false);
				}
				{
					jLabel1 = new JLabel();
					jPanel1.add(jLabel1);
					jLabel1.setText("Id Rodamiento:");
					jLabel1.setBounds(12, 89, 113, 16);
				}
				ventana.setTitle("Modificar Rodamiento");
				ventana.setLocationRelativeTo(null);
				ventana.setVisible(true);
				ventana.pack();
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private void btnBuscarRodamientoActionPerformed(ActionEvent evt) {
		Rodamiento rod =((ControladorRodamiento)getControladorrodamientos()).buscarRodamiento(txtCodRodamiento.getText());
		jTextField1.setText(String.valueOf(rod.getIdRodamiento()));
		txtDesc.setText(rod.getDescripcion());
		txtMarca.setText(rod.getMarca());
		txtOrigen.setText(rod.getOrigen());
	}
	
	private void btnModificarRodamientoActionPerformed(ActionEvent evt) {
		((ControladorRodamiento)getControladorrodamientos()).modificarRodamiento(Long.parseLong(jTextField1.getText()), txtCodRodamiento.getText(),txtDesc.getText(), txtMarca.getText(), txtOrigen.getText());
	}
	
	private void btnCancelarActionPerformed(ActionEvent evt) {
		this.ventana.dispose();
	}

	private JPanel jPanel1;
	private JLabel lblDesc;
	private JLabel jLabel1;
	private JTextField jTextField1;
	private JButton btnCancelar;
	private JButton btnModificarRodamiento;
	private JTextField txtOrigen;
	private JLabel lblOrigen;
	private JTextField txtMarca;
	private JLabel lblMarca;
	private JTextField txtDesc;
	private JTextField txtCodRodamiento;
	private JLabel lblCodRodamiento;
	private JButton btnBuscarRodamiento;


}

